<?php
session_start();
require 'database/photo_handler.php';
require 'database/search_handler.php';
require 'database/profile_handler.php';
require 'database/follower_handler.php';

if (isset($_GET["SearchOk"])) {
    $query = $_GET["SearchBar"];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Search Results</title>
        <script type="text/javascript" src="script/validator.js"></script>
        <script type="text/javascript" src="script/calendar.js"></script>
        <script type="text/javascript" src="script/ajax.js"></script>
        <link rel="stylesheet" href="style/style.css" />
    </head>
    <body onload="HideCalendar()" >
<?php
if ($_GET['gagal'] == 1) {
?>
        <script type="text/javascript">alert("Login failed");</script>
<?
}

if ($_GET['reg'] == 1) {
    echo "<font color='green'>Registration Successfull</font>";
}
?>
        <div id="container">
            <div id="headerBody">
                <form id="Search" name="Search" method ="GET" action="search_result.php">

                    <input type="text" id="SearchBar" name="SearchBar"/>

                    <input type="submit" id="SearchOk" name="SearchOk" value="Search"/>
                </form>
<?php if ($_SESSION['Username'] != null) {
?>
                <a id="headerLink" href="javascript:viewHome();" id="headerLink">Home</a>
                <a id="headerLink" href="javascript:showPopupProfile();" id="headerLink">Profile</a>
                <a id="headerLink" href="javascript:viewMessage();" id="headerLink">Message</a>
                <a id="headerLink" href="javascript:viewUploader();" id="headerLink">Uploader</a>
                <a id="headerLink" href="javascript:viewGallery();" id="headerLink">Gallery</a>
                <a href="database/login.php?logout=1" id="logout_link" >Logout</a>
                <a href="chat.php" id="logout_link" >Chat</a>
                <a href="javascript:viewProfile();" id="logout_link" ><?php echo $_SESSION['Username']; ?></a>
                <a href="javascript:showNotif('<?php echo $_SESSION['Username']; ?>');" id="headerLink">Notification</a>
                <!-- tampilin jumlah notif -->
<?php
                require_once 'database/notif_handler.php';

                $notif = new notif_handler();
                $jml = 0;

                $notif->retr_notification($_SESSION['Username']);
                if (count($notif->berita) > 0 && $notif->berita[0] != null) {
                    for ($i = 0; $i < count($notif->berita); $i++) {
                        if ($notif->read[$i] == 0) {
                            $jml++;
                        }
                    }
                    if ($jml > 0)
                        echo "<font color='red'>(" . $jml . ")</font>";
                }
                else {
                    echo "";
                }
?>
                <div id="profile_popup">
                </div>
                <div id="notif">
                    <div id="notif2">
                    </div>
                </div>
                <a href="profile.php" id="logout_link" ><?php echo $u; ?></a>
<?php } else { ?>
                <a href="index.php" id="logout_link" >Login</a>
<?php
            }
?>
            </div>
            <div id=""><img src="images/flickertiew_logo.gif" alt=""/></div>
<?php
            //require 'header.php';

            $SH = new search_handler();
?>
            <div id="centerBody">
            <div id="content">
                <div id="_title2">Search Result for "<?php echo $query; ?>" : </div><br/>
			User : <br/><br/>
                <div id="message_container">
                    <div id="message_content">
                        <br/>
<?php
            $SH->search_user($query); //dapat nama dan username
            if (count($SH->nama) == 0) {
                echo "No user found!" . "<br />";
            } else {
                $iterator = 0;
                for ($i = 0; $i < count($SH->nama); $i++) { //tampilkan 1-1
                    $Profile = new profile_handler();
                    $Profile->get_wall_privacy($SH->username[$i]);
                    $Follower = new follower_handler();
                    if (($Profile->result[0] == "all members") || (($Profile->result[0] == "just followers") && ($Follower->is_follow($_SESSION['Username'], $SH->username[$i])))) {
                        $iterator++;
?>
                        <a id="headerLink" href="otherprofile.php?UserTujuan=<? echo $SH->username[$i] ?>"> <? echo $SH->nama[$i] ?></a><br/>
                        <?
                    } else {
                        
                    }
                }
                if ($iterator == 0) {
                    echo "No user found!" . "<br />";
                }
            }
                        ?>
                        <br/>
                        <br/>
                    </div>
                </div>
                        <?
                        ?>
                <br/> Photo : <br /><br/>
                <div id="message_container">
                    <div id="message_content">
                        <br/>
                        <br/>
<?
                        $SH->search_photo($query); //dapat nama dan username
                        if (count($SH->img_url) == 0) {
                            echo "No photo found!" . "<br />";
                        } else {
                            for ($i = 0; $i < count($SH->img_url); $i++) { //tampilkan 1-1
                                $iterator = 0;
                                $Follower = new follower_handler();
                                $Photo = new photo_handler();
                                $kodok = $SH->img_url[$i];
                                $query = "SELECT photo_id FROM photo WHERE url = '$kodok'";
                                $Photo->exec_q($query, "photo_id");

                                $id = $Photo->result[0];
                                $Photo->retr_photo_details($id, 6);

                                if (($Photo->result[0] == "everyone") || (($Photo->result[0] == "members only") && $_SESSION['Username'] != NULL) || (($Photo->result[0] == "just followers") && ($Follower->is_follow($_SESSION['Username'], $SH->username[$i])))) {
?>
                                    <a a href="gallery.php?view=2&photo_id=<?php echo $SH->photo_id[$i]; ?>" alt=""><img src="<? echo $SH->img_url[$i] ?>" alt="" height ="150" height="150"/></a>
                        <?
                                    $iterator++;
                                }
                            }
                            if ($iterator == 0) {
                                echo "No photo found!" . "<br />";
                            }
                        }
                        ?>
                    </div>
                </div>
                <br/>
                <br/>
            </div>
                <div id="footerBody">
                    <div id="footer" align="center">
                        Copyright &copy; 2011<br/>
                        Created by <a href="http://www.facebook.com/Gunawan.Robert" id="headerLink">Robert Gunawan</a>
						, <a href="http://www.facebook.com/danz3m" id="headerLink">Danang Tri Massandy</a>, 
                        <a href="http://www.facebook.com/achmad.giovani" id="headerLink">Achmad Giovani</a>
                    </div>
                </div>
            </div>
        </div>





    </body>
</html>
